package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.PlanList;

/**
 * editor: HuXiaoDan
 * time: 2016/12/12 16:12
 */
public class PlanApproveDetailFragment extends Fragment {
  protected static final String EXTRA_CONTENT =
      "com.isunland.managesystem.ui.PlanApproveDetailFragment.EXTRA_CONTENT";
  private PlanList.PlanCheckList mContent;
  private TextView mtvPlanContent;
  private TextView mtvPlanKind;
  private TextView mtvPlanEsteTime;
  private TextView mtvAppointer;
  private TextView mtvExecutor;
  //private TextView mtvPlanTimeDesc;
  private TextView mtvCorporator;
  //private TextView mtvApplicator;
  private TextView mtvRegister;
  private TextView mtvRegisterTime;
  //private TextView mtvProjectName;
  //private TextView mtvExtraFile;

  //private String mDocPath = "";

  public static PlanApproveDetailFragment newInstance(PlanList.PlanCheckList content) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_CONTENT, content);
    PlanApproveDetailFragment fragment = new PlanApproveDetailFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    ActionBar actionBar = ((BaseVolleyActivity) getActivity()).getSupportActionBar();
    if (actionBar != null) {

      actionBar.setTitle(R.string.planApproveDetail);
      actionBar.setDisplayHomeAsUpEnabled(true);
    }
    mContent = (PlanList.PlanCheckList) getArguments().getSerializable(EXTRA_CONTENT);
    //if (mContent != null) {
    //
    //    mDocPath = mContent.getDocPath();
    //}

    super.onCreate(savedInstanceState);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_plan_detail, container, false);
    findViews(view);
    initData();
    return view;
  }

  private void findViews(View view) {
    mtvPlanContent = (TextView) view.findViewById(R.id.tv_planContent);
    mtvPlanKind = (TextView) view.findViewById(R.id.tv_planKind);
    mtvPlanEsteTime = (TextView) view.findViewById(R.id.tv_planEsteTime);
    mtvAppointer = (TextView) view.findViewById(R.id.tv_appointer);
    mtvExecutor = (TextView) view.findViewById(R.id.tv_executor);
    //mtvPlanTimeDesc = (TextView) view.findViewById(R.id.tv_planTimeDesc);
    mtvCorporator = (TextView) view.findViewById(R.id.tv_corporator);
    //mtvApplicator = (TextView) view.findViewById(R.id.tv_applicator);
    mtvRegister = (TextView) view.findViewById(R.id.tv_register);
    mtvRegisterTime = (TextView) view.findViewById(R.id.tv_registerTime);
    //mtvProjectName = (TextView) view.findViewById(R.id.tv_projectName);
    //mtvExtraFile = (TextView) view.findViewById(R.id.tv_extraFile);
    //mtvExtraFile.setOnClickListener(new View.OnClickListener() {
    //    @Override
    //    public void onClick(View view) {
    //        if (!TextUtils.isEmpty(mDocPath)) {
    //            ExtraDownLoadDialogFragment dialog = ExtraDownLoadDialogFragment.newInstance("", mDocPath);
    //            FragmentManager fm = getActivity().getSupportFragmentManager();
    //            dialog.show(fm, "");
    //        }
    //    }
    //});
  }

  private void initData() {
    mtvPlanContent.setText(mContent.getPlanContentDesc());
    mtvPlanKind.setText(mContent.getPlanKindName());
    mtvPlanEsteTime.setText(mContent.getPlanEsteTime());
    mtvAppointer.setText(mContent.getTaskManName());
    mtvExecutor.setText(mContent.getExcManName());
    //mtvPlanTimeDesc.setText(mContent.getPlanTimeDesc());
    mtvCorporator.setText(mContent.getCoopManNames());
    //mtvApplicator.setText(mContent.getRegStaffName());
    mtvRegister.setText(mContent.getRegStaffName());
    mtvRegisterTime.setText(mContent.getRegDate());
    //mtvProjectName.setText(mContent.getProjectName());
    //mtvExtraFile.setText(mContent.getDocBlob());
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        break;
      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }
}
